package com.youyi.yyviewsdklibrary.Dialog.core;

import android.content.Context;
import android.graphics.Rect;
import com.youyi.yyviewsdklibrary.Dialog.XPopup;
import com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.ScrollScaleAnimator;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupAnimation;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupPosition;
import com.youyi.yyviewsdklibrary.Dialog.util.XPopupUtils;

public class HorizontalAttachPopupView extends AttachPopupView {
    public HorizontalAttachPopupView(Context context) {
        super(context);
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView, com.youyi.yyviewsdklibrary.Dialog.core.AttachPopupView
    public void initPopupContent() {
        super.initPopupContent();
        this.defaultOffsetY = this.popupInfo.offsetY;
        this.defaultOffsetX = this.popupInfo.offsetX == 0 ? XPopupUtils.dp2px(getContext(), 2.0f) : this.popupInfo.offsetX;
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.core.AttachPopupView
    public void doAttach() {
        float f;
        float f2;
        int i;
        int i2;
        float f3;
        boolean isLayoutRtl = XPopupUtils.isLayoutRtl(getContext());
        int measuredWidth = getPopupContentView().getMeasuredWidth();
        int measuredHeight = getPopupContentView().getMeasuredHeight();
        boolean z = true;
        if (this.popupInfo.touchPoint != null) {
            if (XPopup.longClickPoint != null) {
                this.popupInfo.touchPoint = XPopup.longClickPoint;
            }
            if (this.popupInfo.touchPoint.x <= ((float) (XPopupUtils.getAppWidth(getContext()) / 2))) {
                z = false;
            }
            this.isShowLeft = z;
            if (isLayoutRtl) {
                if (this.isShowLeft) {
                    f3 = (((float) XPopupUtils.getAppWidth(getContext())) - this.popupInfo.touchPoint.x) + ((float) this.defaultOffsetX);
                } else {
                    f3 = ((((float) XPopupUtils.getAppWidth(getContext())) - this.popupInfo.touchPoint.x) - ((float) getPopupContentView().getMeasuredWidth())) - ((float) this.defaultOffsetX);
                }
                f2 = -f3;
            } else {
                f2 = isShowLeftToTarget() ? (this.popupInfo.touchPoint.x - ((float) measuredWidth)) - ((float) this.defaultOffsetX) : this.popupInfo.touchPoint.x + ((float) this.defaultOffsetX);
            }
            f = (this.popupInfo.touchPoint.y - (((float) measuredHeight) * 0.5f)) + ((float) this.defaultOffsetY);
        } else {
            Rect atViewRect = this.popupInfo.getAtViewRect();
            if ((atViewRect.left + atViewRect.right) / 2 <= XPopupUtils.getAppWidth(getContext()) / 2) {
                z = false;
            }
            this.isShowLeft = z;
            if (isLayoutRtl) {
                if (this.isShowLeft) {
                    i2 = (XPopupUtils.getAppWidth(getContext()) - atViewRect.left) + this.defaultOffsetX;
                } else {
                    i2 = ((XPopupUtils.getAppWidth(getContext()) - atViewRect.right) - getPopupContentView().getMeasuredWidth()) - this.defaultOffsetX;
                }
                i = -i2;
            } else {
                i = isShowLeftToTarget() ? (atViewRect.left - measuredWidth) - this.defaultOffsetX : atViewRect.right + this.defaultOffsetX;
            }
            f2 = (float) i;
            f = (float) (atViewRect.top + ((atViewRect.height() - measuredHeight) / 2) + this.defaultOffsetY);
        }
        getPopupContentView().setTranslationX(f2 - ((float) getActivityContentLeft()));
        getPopupContentView().setTranslationY(f);
        initAndStartAnimation();
    }

    private boolean isShowLeftToTarget() {
        return (this.isShowLeft || this.popupInfo.popupPosition == PopupPosition.Left) && this.popupInfo.popupPosition != PopupPosition.Right;
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView, com.youyi.yyviewsdklibrary.Dialog.core.AttachPopupView
    public PopupAnimator getPopupAnimator() {
        ScrollScaleAnimator scrollScaleAnimator;
        if (isShowLeftToTarget()) {
            scrollScaleAnimator = new ScrollScaleAnimator(getPopupContentView(), getAnimationDuration(), PopupAnimation.ScrollAlphaFromRight);
        } else {
            scrollScaleAnimator = new ScrollScaleAnimator(getPopupContentView(), getAnimationDuration(), PopupAnimation.ScrollAlphaFromLeft);
        }
        scrollScaleAnimator.isOnlyScaleX = true;
        return scrollScaleAnimator;
    }
}
